var app = getApp();
Component({
  properties: {
    attr:{
      type: Object,
      value: {}
    }
  },
  data: {},
  attached: function () {},
  methods: {
    specitem: function (e) {
      var indexw = e.currentTarget.dataset.id;
      var indexn = e.currentTarget.dataset.id2;
      this.data.attr.productAttr[indexw].index = indexn;
      var value = this.getCheckedValue()
        .sort()
        .join(",");
      this.triggerEvent("changeattr", { value: value,attr:this.data.attr});
    },
    //获取被选中属性；
    getCheckedValue: function () {
      let productAttr = this.data.attr.productAttr;
      let value = [];
      for (let i = 0; i < productAttr.length; i++) {
        for (let j = 0; j < productAttr[i].attr_values.length; j++) {
          if (productAttr[i].index === j) {
            value.push(productAttr[i].attr_values[j]);
          }
        }
      }
      return value;
    },
    closeAttr:function(){
      this.triggerEvent('myattr', false);
    },
    joinCart: function () {
      if (this.data.attr.productSelect.stock > 0) {
        this.triggerEvent("gocat", false);
      }
    },
    attrReduce: function () {
      this.triggerEvent("attrreduce");
    }
  }
})